package com.example.uiclassassignments.Activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;

import com.example.uiclassassignments.R;
import com.example.uiclassassignments.tools.Intents;
import com.example.uiclassassignments.tools.ToastUtils;

import de.hdodenhof.circleimageview.CircleImageView;

public class LoginActivity extends Activity {
    EditText et_username, et_password;
    CircleImageView tou_image;
    CheckBox cb;
    String name = "dzy";
    String password = "123456";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        initView();
    }

    public void initView() {
        et_password = findViewById(R.id.et_password);
        et_username = findViewById(R.id.et_username);
        cb = findViewById(R.id.cb);
    }

    /*登录*/
    public void login(View view) {
        if (name.contentEquals(et_username.getText())) {
            if (password.contentEquals(et_password.getText())) {
                if (cb.isChecked()) {
                    ToastUtils.showTextToas(this, "登录成功");
                    finish();
                    Intents.Intent(this, MainActivity.class, null);
                } else {
                    ToastUtils.showTextToas(this, "请同意勾选");
                }
            } else {
                ToastUtils.showTextToas(this, "密码或账户错误");
            }
        } else {
            ToastUtils.showTextToas(this, "密码或账户错误");
        }
    }

    /*取消*/
    public void exit(View view) {
        onBackPressed();
    }

    /*双重退出*/
    private long lostClickTime = 0;

    @Override
    public void onBackPressed() {
        //按键时间差
        if (lostClickTime <= 0) {
            ToastUtils.showTextToas(this, "再按一此退出应用");
            lostClickTime = System.currentTimeMillis();
        } else {
            long currentClickTime = System.currentTimeMillis();
            if (currentClickTime - lostClickTime < 1000) {
                finish();
                ToastUtils.showTextToas(this, "软件已退出");
            } else {
                lostClickTime = currentClickTime;
                ToastUtils.showTextToas(this, "再按一此退出应用");
            }
        }
    }
}
